/**
 *******************************************************************************
 * @FileName  : spp_main.h
 * @Author    : GaoQiu
 * @CreateDate: 2020-05-18
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 *
 * The information contained herein is confidential and proprietary property of
 * GaoQiu and is available under the terms of Commercial License Agreement
 * between GaoQiu and the licensee in separate contract or the terms described
 * here-in.
 *
 * This heading MUST NOT be removed from this file.
 *
 * Licensees are granted free, non-transferable use of the information in this
 * file under Mutual Non-Disclosure Agreement. NO WARRENTY of ANY KIND is provided.
 *
 *******************************************************************************
 */

#ifndef SPP_MAIN_C_
#define SPP_MAIN_C_

#include <stdint.h>
#include "utils/stimer.h"
#include "utils/mdc.h"

#define SPP_RX_BUF_SIZE     1024

#define SPP_HDR_LEN    4



/*!< SPP Command Type */
#define SPP_CMD_TYPE_CFG    0x01
#define SPP_CMD_TYPE_BLE    0x02
#define SPP_CMD_TYPE_TRACK  0x03
#define SPP_CMD_TYPE_DFU    0x04
#define SPP_CMD_TYPE_MAX    SPP_CMD_TYPE_DFU

/*!< SPP Opcode: CFG */
#define SPP_CFG_OPCODE_SET_MAC_ADDR       0x01
#define SPP_CFG_OPCODE_GET_MAC_ADDR       0x02
#define SPP_CFG_OPCODE_SET_TX_POWER       0x03
#define SPP_CFG_OPCODE_SET_FILTER_MAC     0x04
#define SPP_CFG_OPCODE_GET_FILTER_MAC     0x05
#define SPP_CFG_OPCODE_CLR_FILTER_MAC     0x06
#define SPP_CFG_OPCODE_MAX                SPP_CFG_OPCODE_CLR_FILTER_MAC

/*!< SPP Opcode: BLE */
#define SPP_BLE_OPCODE_SET_ADV_PARAM      0x01
#define SPP_BLE_OPCODE_SET_ADV_DATA       0x02
#define SPP_BLE_OPCODE_SET_SCAN_RSP_DATA  0x03
#define SPP_BLE_OPCODE_SET_ADV_ENABLE     0x04
#define SPP_BLE_OPCODE_MAX                SPP_BLE_OPCODE_SET_ADV_ENABLE

enum{
	SPP_STATE_RX_HDR     = 0,
 	SPP_STATE_RX_PAYLOAD = 1,
};

typedef struct{
	union{
		struct{
			uint8_t   type;
			uint8_t   opcode;
		};
		uint16_t      cmd;
	};
	uint16_t  pldLen;
	uint8_t   data[1];
}SppFrame_t;


typedef struct{
	MdcHandlerId_t    handlerId;
	MdcTimer_t        timeoutTimer;

	uint8_t           *pRxBuf;
	uint32_t           rxBufSize;
	uint16_t           rxCnt;
	uint16_t           plyLen;
	uint8_t            state;
	uint8_t            initialized;
}SPPCb_t;

SPPCb_t SppCb;


enum{
	SPP_MDC_EVT_TIMEOUT  = 0x0001,
};


#endif /* SPP_MAIN_C_ */
